home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / netmail / rnr214.zip / RNRINIT.PAS < prev    next >
Pascal/Delphi Source File  |  1996-04-03  |  65KB  |  2,431 lines

  1. unit rnrinit;
  2.  
  3. {
  4.  
  5. rnrinit.pas - rnr initialization
  6.  
  7. }
  8.  
  9. {$I rnr-def.pas}
  10.  
  11. interface
  12.  
  13. uses dos,crt,genericf,colornms,nwid,rnrglob,rnrconf,rnrio,rnrfile,
  14.  rnrfunc,rnrproc,rnrkill,rnrmous
  15.  
  16. {$ifdef timeout}
  17. ,rnrtime
  18. {$endif}
  19.  
  20. {$ifdef charset}
  21. ,rnrchar
  22. {$endif}
  23.  
  24. ;
  25.  
  26. const
  27.   issuspicious=true;
  28.   notsuspicious=false;
  29.  
  30. procedure initialize;
  31. procedure justhandleset(setline: string; suspicious: boolean);
  32. procedure justhandleunset(setline: string; suspicious: boolean);
  33.  
  34. implementation
  35.  
  36. var
  37.   foundtrusted: boolean;
  38.   defaultfromwidth: integer;
  39.   defaultsizewidth: integer;
  40.  
  41. procedure usage;
  42.  
  43. begin
  44.   xwritelnsss('usage: ',newsreadername,' [options]');
  45.   xwritelns('  -u --user %A');
  46.   xwritelns('  -n --newsgroup c.b.w (jumps directly to that newsgroup)');
  47.   xwritelns('  -p --port 1 (uses that fossil port - 1=COM1, 2=COM2)');
  48.   xwritelns('  -f --fullname Full_Name (underscores will become spaces)');
  49.   xwritelns('  -e --editor d:/path/editor[.exe] (uses this editor)');
  50.   xwritelns('  -o --editor-options !_w:\user\%A (editor non-filename options)');
  51.   xwritelns('  -s --forum-set-list local_usenet (uses these forum sets only)');
  52.   xwritelns('  -t --trusted (allows dialin users to edit articles)');
  53.   xwritelns('  -i --interface (specify waffle or uupc file layout)');
  54.   xwritelns('  -v --interface-version %V (specifies interface version)');
  55.   xwritelns('  -m --minutes %O (specifies minutes online time, or -1)');
  56.   xwritelns('  -d --shadow 1 (shadows all COMx output to console)');
  57.   xwritelns('  -r --rcfile w:/waffle/lib/rnr.opt (reads in options)');
  58.   xwriteln;
  59.   xwritelns('see documentation for other configuration options');
  60.   xwriteln;
  61.   xwritelns('Russell_Schulz@locutus.ofB.ORG ('+releasedate+')');
  62.   xwritelns('Adapted for UUPC by storner@osiris.ping.dk (941204)');
  63.   shutdown(1);
  64. end;
  65.  
  66. procedure defaultlppcols;
  67.  
  68. begin
  69.   if console then
  70.     begin
  71.       if detectvideo then
  72.         begin
  73.           lpp := mem[$40:$84]+1;
  74.           cols := mem[$40:$4a];
  75.         end
  76.       else
  77.         begin
  78.           lpp := 25;
  79.           cols := 80
  80.         end;
  81.     end
  82.   else
  83.     begin
  84.       lpp := 24;
  85.       cols := 80;
  86.     end;
  87. end;
  88.  
  89. procedure fixuplppcols;
  90.  
  91. begin
  92.   lpp := max(minlpp,min(lpp,maxlpp));
  93.   cols := max(mincols,min(cols,maxcols));
  94.  
  95. {26 letters+10 digits for toggles}
  96.  
  97.   sellpp := min(lpp-selheaderlines-4,36);
  98. end;
  99.  
  100. procedure backupjoin;
  101.  
  102. var
  103.   groupline: string;
  104.   tempf: text;
  105.   createjoined: boolean;
  106.  
  107. begin
  108.   xwritelns('Backing up join file...');
  109.  
  110.   createjoined := (numjoined=0);
  111.  
  112.   assign(tempf,home+'\join.bak');
  113.   rewrite(tempf);
  114.  
  115.   reset(joinf);
  116.   while not eof(joinf) do
  117.     begin
  118.       readln(joinf,groupline);
  119.       writeln(tempf,groupline);
  120.       if createjoined and (numjoined<maxjoined) then
  121.         begin
  122.           inc(numjoined);
  123.           joinedgroups[numjoined] := getfirstw(groupline);
  124.         end;
  125.     end;
  126.  
  127.   close(tempf);
  128.   reset(joinf);
  129. end;
  130.  
  131. procedure fixpathuserid;
  132.  
  133. begin
  134. { only do this if we've been able to run translateuserid -- so this }
  135. { means that this routine _must_ be called after translateuserid too }
  136.   if configdir<>'' then
  137.     begin
  138.       if pathuserid='' then
  139.         pathuserid := userid;
  140.       pathuserid := wafexpand(pathuserid);
  141.     end;
  142.  
  143. end;
  144.  
  145. procedure fixfromuserid;
  146.  
  147. begin
  148. { only do this if we've been able to run translateuserid -- so this }
  149. { means that this routine _must_ be called after translateuserid too }
  150.   if configdir<>'' then
  151.     begin
  152.       if fromuserid='' then
  153.         fromuserid := userid;
  154.       fromuserid := wafexpand(fromuserid);
  155.     end;
  156. end;
  157.  
  158. procedure fixcustomstatic;
  159.  
  160. begin
  161. { only do this if we've been able to run translateuserid -- so this }
  162. { means that this routine _must_ be called after translateuserid too }
  163.   if configdir<>'' then
  164.     customstatic := wafexpand(customstatic);
  165. end;
  166.  
  167. procedure fixnewscmdline;
  168.  
  169. begin
  170.   if newscmdline='(standard)' then
  171.     newscmdline := getsyscmd('news');
  172.  
  173.   if newscmdline='' then
  174.     newscmdline := 'rnews';
  175.  
  176.   newscmdline := unslash(newscmdline);
  177.  
  178.   if newscmdline=builtincookie then
  179.     begin
  180.       xwritelns('error:  there is no builtin newscmdline');
  181.       shutdown(1);
  182.     end;
  183. end;
  184.  
  185. procedure fixmailcmdline;
  186.  
  187. begin
  188.   if mailcmdline='(standard)' then
  189.     mailcmdline := getsyscmd('mail');
  190.  
  191.   if mailcmdline='' then
  192.     mailcmdline := builtincookie;
  193.  
  194.   mailcmdline := unslash(mailcmdline);
  195. end;
  196.  
  197. procedure fixcolors;
  198.  
  199. var
  200.   mangledcolors: string;
  201.  
  202. begin
  203.   lowcolor := 7;
  204.   highcolor := 15;
  205.  
  206.   if colors='' then
  207.     colors := getconfig('colors');
  208.  
  209.   if colors='' then
  210.     colors := getconfig('colours');
  211.  
  212.   if colors<>'' then
  213.     begin
  214.       mangledcolors := colors;
  215.       lowcolor := colortoi(chopfirstw(mangledcolors));
  216.       highcolor := colortoi(getfirstw(mangledcolors));
  217.     end;
  218.  
  219.   if (lowcolor mod 16)=(highcolor mod 16) then
  220.     if (lowcolor mod 16)=7 then
  221.       highcolor := 15
  222.     else
  223.       lowcolor := 7;
  224.  
  225.   if quotecolor=255 then
  226.     quotecolor := lowcolor;
  227.  
  228.   if alternatecolor=255 then
  229.     alternatecolor := lowcolor;
  230. end;
  231.  
  232. procedure handlemap(cmdline: string);
  233.  
  234. var
  235.   where: string;
  236.   oldkey,newkey: char;
  237.   newcmdline: string;
  238.  
  239. function whatch: char;
  240.  
  241. var
  242.   result: char;
  243.   donescan: boolean;
  244.  
  245. begin
  246.   result := chr(0);
  247.  
  248.   if newcmdline<>'' then
  249.     begin
  250.       if (newcmdline[1]='\') and (length(newcmdline)>1) then
  251.         begin
  252.           result := newcmdline[2];
  253.           newcmdline := lchop(newcmdline,2);  {get rid of it and the backslash}
  254.         end
  255.       else if (newcmdline[1]='=') and (length(newcmdline)>1) then
  256.         begin
  257.           newcmdline := lchop(newcmdline,1);  {get rid of the equals}
  258.           donescan := false;
  259.           while not donescan do
  260.             begin
  261.               if length(newcmdline)=0 then
  262.                 donescan := true     {no more to see}
  263.               else if (newcmdline[1]<'0') or (newcmdline[1]>'9') then
  264.                 donescan := true     {no more digits, anyway}
  265.               else
  266.                 begin
  267.                   result := chr(10*ord(result)+ord(newcmdline[1])-ord('0'));
  268.                   newcmdline := lchop(newcmdline,1);   {get rid of digit}
  269.                 end;
  270.             end;
  271.         end
  272.       else
  273.         begin
  274.           result := newcmdline[1];
  275.           newcmdline := lchop(newcmdline,1);
  276.         end;
  277.     end;
  278.  
  279.   whatch := result;
  280. end;
  281.  
  282. begin {handlemap}
  283.   newcmdline := cmdline;
  284.   newkey := chr(0);
  285.   oldkey := chr(0);
  286.   where := chopfirstw(newcmdline);
  287.   newcmdline := ltrim(newcmdline);
  288.   oldkey := whatch;
  289.   newcmdline := ltrim(newcmdline);
  290.   newkey := whatch;
  291.  
  292.   if (oldkey<>chr(0)) and (newkey<>chr(0)) then
  293.     begin
  294.       if where='browse' then
  295.         begin
  296.           browsemap[oldkey] := newkey;
  297.         end
  298.       else if where='select' then
  299.         begin
  300.           selmap[oldkey] := newkey;
  301.         end
  302.       else if where='both' then
  303.         begin
  304.           browsemap[oldkey] := newkey;
  305.           selmap[oldkey] := newkey;
  306.         end
  307.       else if where='main' then
  308.         begin
  309.           mainmap[oldkey] := newkey;
  310.         end
  311.       else
  312.         begin
  313.           warn('weird use of map - ignored '+cmdline);
  314.         end;
  315.     end
  316.   else
  317.     begin
  318.       warn('weird use of map - ignored '+cmdline);
  319.     end;
  320. end; {handlemap}
  321.  
  322. procedure maybesetopts(tag: string; var result: string;
  323.   newval: string; mayuserestrictedopts: boolean);
  324.  
  325. begin
  326.   if mayuserestrictedopts then
  327.     result := newval
  328.   else
  329.     warn('without -t, cannot use '+tag+' here');
  330. end;
  331.  
  332. procedure maybesetoptp(tag: string; var result: pathstring;
  333.   newval: string; mayuserestrictedopts: boolean);
  334.  
  335. begin
  336.   if mayuserestrictedopts then
  337.     result := newval
  338.   else
  339.     warn('without -t, cannot use '+tag+' here');
  340. end;
  341.  
  342. procedure maybesetoptsh(tag: string; var result: shortstring;
  343.   newval: string; mayuserestrictedopts: boolean);
  344.  
  345. begin
  346.   if mayuserestrictedopts then
  347.     result := newval
  348.   else
  349.     warn('without -t, cannot use '+tag+' here');
  350. end;
  351.  
  352. procedure maybesetopti(tag: string; var result: integer;
  353.   newval: integer; mayuserestrictedopts: boolean);
  354.  
  355. begin
  356.   if mayuserestrictedopts then
  357.     result := newval
  358.   else
  359.     warn('without -t, cannot use '+tag+' here');
  360. end;
  361.  
  362. procedure maybesetoptb(tag: string; var result: boolean;
  363.   newval: boolean; mayuserestrictedopts: boolean);
  364.  
  365. begin
  366.   if mayuserestrictedopts then
  367.     result := newval
  368.   else
  369.     warn('without -t, cannot use '+tag+' here');
  370. end;
  371.  
  372. function handleset(setline: string; suspicious: boolean): boolean;
  373.  
  374. var
  375.   usedarg: boolean;
  376.   mayuserestrictedopts: boolean;
  377.  
  378.   tag: string;
  379.   avalue: string;
  380.   lavalue: string;
  381.   bvalue: boolean;
  382.  
  383.   equalpos: integer;
  384.  
  385. begin
  386.   usedarg := false;
  387.  
  388. {$ifdef trustedusersmayputrestrictedoptsinuserrcfile}
  389.   mayuserestrictedopts := trusted or (not suspicious);
  390. {$else}
  391.   mayuserestrictedopts := not suspicious;
  392. {$endif}
  393.  
  394. {handle "set foo", "set --foo", "set foo 3", and "set foo=3"}
  395.  
  396.   avalue := trim(ltrim(setline));
  397.   equalpos := pos('=',avalue);
  398.   if equalpos=0 then
  399.     tag := chopfirstw(avalue)
  400.   else
  401.     begin
  402.       tag := copy(avalue,1,equalpos-1);
  403.       avalue := copy(avalue,equalpos+1,255);
  404.     end;
  405.  
  406.   tag := lower(tag);
  407.  
  408.   bvalue := true;
  409.   lavalue := lower(avalue);
  410.   if (lavalue='false') or
  411.    (lavalue='f') or
  412.    (lavalue='off') or
  413.    (lavalue='0') or
  414.    (lavalue='no') then
  415.     bvalue := false;
  416.  
  417.   if copy(tag,1,2)='--' then
  418.     tag := lchop(tag,2);
  419.  
  420.   if (tag='-e') or (tag='editor') then
  421.     begin
  422.       maybesetoptp(tag,editor,avalue,mayuserestrictedopts);
  423.       usedarg := true;
  424.     end
  425.   else if (tag='-o') or (tag='editor-options') then
  426.     begin
  427.       maybesetoptp(tag,editoroptions,
  428.        ununderscore(avalue),mayuserestrictedopts);
  429.       usedarg := true;
  430.     end
  431.   else if (tag='-d') or (tag='shadow') then
  432.     begin
  433.       maybesetopti(tag,shadow,atoi(avalue),mayuserestrictedopts);
  434.       usedarg := true;
  435.     end
  436.   else if tag='vspeller' then
  437.     begin
  438.       maybesetoptp(tag,vspeller,avalue,mayuserestrictedopts);
  439.       usedarg := true;
  440.     end
  441.   else if tag='vspeller-options' then
  442.     begin
  443.       maybesetoptp(tag,vspelleroptions,avalue,mayuserestrictedopts);
  444.       usedarg := true;
  445.     end
  446.   else if tag='subjects-case-insensitive' then
  447.     subjectscaseinsensitive := bvalue
  448.   else if tag='subject-length' then
  449.     begin
  450.       subjectlength := atoi(avalue);
  451.       if subjectlength<5 then
  452.         begin
  453.           subjectlength := 5;
  454.           xwrites('using subject-length of ');
  455.           xwritei(subjectlength);
  456.           xwriteln;
  457.         end;
  458.       if subjectlength>maxsubjectlen then
  459.         begin
  460.           subjectlength := maxsubjectlen;
  461.           xwrites('using subject-length of ');
  462.           xwritei(subjectlength);
  463.           xwriteln;
  464.         end;
  465.       usedarg := true;
  466.     end
  467.   else if tag='squash-spaces' then
  468.     squashspaces := bvalue
  469.   else if tag='equate-truncated' then
  470.     begin
  471.       equatetruncated := atoi(avalue);
  472.       if equatetruncated<5 then
  473.         begin
  474.           xwritelns('using equate-truncated of 5');
  475.           equatetruncated := 5;
  476.         end;
  477.       usedarg := true;
  478.     end
  479.   else if tag='make-space-like-x' then
  480.     makespacelikex := bvalue
  481.   else if tag='make-return-like-asterisk' then
  482.     begin
  483.       xwritelns('warning: obsolete option --make-return-like-asterisk');
  484.       xwritelns('warning: use --map select =13 * instead');
  485.       handlemap('select =13 *');
  486.     end
  487.   else if tag='hide-these-headers' then
  488.     begin
  489.       hideheaders := upper(avalue);
  490.       usedarg := true;
  491.     end
  492.   else if tag='show-only-these-headers' then
  493.     begin
  494.       showheaders := upper(avalue);
  495.       usedarg := true;
  496.     end
  497.   else if tag='highlight-these-headers' then
  498.     begin
  499.       highlightheaders := upper(avalue);
  500.       usedarg := true;
  501.     end
  502.   else if tag='no-mail-from' then
  503.     maybesetoptb(tag,nomailfrom,bvalue,mayuserestrictedopts)
  504.   else if tag='no-mail-headers' then
  505.     begin
  506.       maybesetopts(tag,nomailheaders,upper(avalue),mayuserestrictedopts);
  507.       usedarg := true;
  508.     end
  509.   else if tag='no-news-headers' then
  510.     begin
  511.       maybesetopts(tag,nonewsheaders,upper(avalue),mayuserestrictedopts);
  512.       usedarg := true;
  513.     end
  514.   else if tag='wandering-numbers' then
  515.     wanderingnumbers := bvalue
  516.   else if tag='antikill-references' then
  517.     antikillreferences := bvalue
  518.   else if tag='show-subject-kills' then
  519.     showsubjectkills := bvalue
  520.   else if tag='show-from-kills' then
  521.     showfromkills := bvalue
  522.   else if tag='show-subject-antikills' then
  523.     showsubjectantikills := bvalue
  524.   else if tag='show-from-antikills' then
  525.     showfromantikills := bvalue
  526.   else if tag='show-kills' then
  527.     showkills := bvalue
  528.   else if tag='show-antikills' then
  529.     showantikills := bvalue
  530.   else if tag='auto-antikill' then
  531.     autoantikill := bvalue
  532.   else if tag='warn-auto-antikill' then
  533.     warnautoantikill := bvalue
  534.   else if tag='edit-after-vspell' then
  535.     editaftervspell := bvalue
  536.   else if tag='case-insensitive-kill' then
  537.     caseinsensitivekill := bvalue
  538.   else if tag='case-insensitive-antikill' then
  539.     caseinsensitiveantikill := bvalue
  540.   else if tag='substring-subject-kill' then
  541.     substringsubjectkill := bvalue
  542.   else if tag='substring-from-kill' then
  543.     substringfromkill := bvalue
  544.   else if tag='substring-subject-antikill' then
  545.     substringsubjectantikill := bvalue
  546.   else if tag='substring-from-antikill' then
  547.     substringfromantikill := bvalue
  548.   else if tag='quiet' then
  549.     quiet := bvalue
  550.   else if tag='confirm-quit' then
  551.     confirmquit := bvalue
  552.   else if tag='confirm-next' then
  553.     begin
  554.       warn('confirm-next is now confirm-next-group');
  555.       confirmnextgroup := bvalue;
  556.     end
  557.   else if tag='confirm-next-group' then
  558.     confirmnextgroup := bvalue
  559.   else if tag='confirm-next-article' then
  560.     confirmnextarticle := bvalue
  561.   else if tag='missing-subject-is-ok' then
  562.     missingsubjectisok := bvalue
  563.   else if tag='tilde-home' then
  564.     maybesetoptb(tag,tildehome,bvalue,mayuserestrictedopts)
  565.   else if tag='antikill-this-newsreader' then
  566.     antikillthisnewsreader := bvalue
  567.   else if tag='clear-screen-between-groups' then
  568.     clearscreenbetweengroups := bvalue
  569.   else if tag='detect-video' then
  570.     begin
  571.       if mayuserestrictedopts then
  572.         begin
  573.           if console then
  574.             begin
  575.               detectvideo := bvalue;
  576.               defaultlppcols;
  577.             end;
  578.         end;
  579.     end
  580.   else if tag='antikill-even-killed' then
  581.     antikillevenkilled := bvalue
  582.   else if tag='use-bios-for-screen' then
  583.     maybesetoptb(tag,usebiosforscreen,bvalue,mayuserestrictedopts)
  584.   else if tag='hide-form-feeds' then
  585.     hideformfeeds := bvalue
  586.   else if tag='path-userid' then
  587.     begin
  588.       maybesetoptsh(tag,pathuserid,avalue,mayuserestrictedopts);
  589.       usedarg := true;
  590.  
  591.       fixpathuserid;
  592.     end
  593.   else if tag='from-userid' then
  594.     begin
  595.       maybesetoptsh(tag,fromuserid,avalue,mayuserestrictedopts);
  596.       usedarg := true;
  597.  
  598.       fixfromuserid;
  599.     end
  600.   else if tag='custom-static' then
  601.     begin
  602.       maybesetoptp(tag,customstatic,avalue,mayuserestrictedopts);
  603.       usedarg := true;
  604.  
  605.       fixcustomstatic;
  606.     end
  607.   else if tag='halt-on-unknown-groups' then
  608.     haltonunknowngroups := bvalue
  609.   else if tag='mouse-chars-header' then
  610.     begin
  611.       mousecharsheader := avalue;
  612.       usedarg := true;
  613.     end
  614.   else if tag='just-dots' then
  615.     justdots := bvalue
  616.   else if tag='no-filemode' then
  617.     maybesetoptb(tag,nofilemode,bvalue,mayuserestrictedopts)
  618.   else if tag='quit-message' then
  619.     begin
  620.       maybesetopts(tag,quitmessage,ununderscore(avalue),mayuserestrictedopts);
  621.       usedarg := true;
  622.     end
  623.   else if tag='output-separator' then
  624.     begin
  625.       outputseparator := avalue;
  626.       usedarg := true;
  627.     end
  628.   else if tag='news-cmd-line' then
  629.     begin
  630.       maybesetoptp(tag,newscmdline,avalue,mayuserestrictedopts);
  631.       usedarg := true;
  632.  
  633.       fixnewscmdline;
  634.     end
  635.   else if tag='mail-cmd-line' then
  636.     begin
  637.       maybesetoptp(tag,mailcmdline,avalue,mayuserestrictedopts);
  638.       usedarg := true;
  639.  
  640.       fixmailcmdline;
  641.     end
  642.   else if tag='mail-agent' then
  643.     mailagent := bvalue
  644.   else if tag='outgoing-mail' then
  645.     begin
  646.       maybesetopts(tag,outgoingmail,avalue,mayuserestrictedopts);
  647.       usedarg := true;
  648.     end
  649.   else if tag='outgoing-news' then
  650.     begin
  651.       maybesetopts(tag,outgoingnews,avalue,mayuserestrictedopts);
  652.       usedarg := true;
  653.     end
  654.   else if tag='highlight-search-hits' then
  655.     highlightsearchhits := bvalue
  656.   else if (tag='colors') or (tag='colours') then
  657.     begin
  658.       colors := uncomma(ununderscore(avalue));
  659.       usedarg := true;
  660.       fixcolors;
  661.     end
  662.   else if (tag='quote-color') or (tag='quote-colour') then
  663.     begin
  664.       quotecolor := colortoi(avalue);
  665.       usedarg := true;
  666.     end
  667.  
  668. {$ifdef charset}
  669.   else if tag='local-charset' then
  670.     begin
  671.       if mayuserestrictedopts then
  672.         begin
  673.           uselocalcharset := true;
  674.           localcharsetfn := wafexpand(avalue);
  675.         end;
  676.       usedarg := true;
  677.     end
  678. {$endif}
  679.  
  680.   else if tag='rmail-single' then
  681.     maybesetoptb(tag,rmailsingle,bvalue,mayuserestrictedopts)
  682.   else if tag='idle' then
  683.     begin
  684.       maybesetopti(tag,idleminutes,atoi(avalue),mayuserestrictedopts);
  685.       usedarg := true;
  686.     end
  687.   else if tag='swap' then
  688.     begin
  689.       if mayuserestrictedopts then
  690.         swap := avalue;
  691.       usedarg := true;
  692.       if (swap<>'') and (swap<>'no') and (swap<>'disk') and (swap<>'ems') then
  693.         begin
  694.           xwritelns('unknown --swap parameter');
  695.           xwritelns('  --swap no   => no swapping');
  696.           xwritelns('  --swap disk => swap to disk');
  697.           xwritelns('  --swap ems  => swap to EMS or disk');
  698.           shutdown(1);
  699.         end;
  700.     end
  701.   else if tag='article-filename-pattern' then
  702.     begin
  703.       maybesetoptp(tag,articlefilenamepattern,avalue,mayuserestrictedopts);
  704.       usedarg := true;
  705.     end
  706.   else if tag='overview-base-name' then
  707.     begin
  708.       maybesetoptp(tag,overviewbasename,avalue,mayuserestrictedopts);
  709.       usedarg := true;
  710.     end
  711.   else if tag='from-width' then
  712.     begin
  713.       fromwidth := atoi(avalue);
  714.       usedarg := true;
  715.  
  716. {}{ default value should depend on cols }
  717.       if (fromwidth<5) or (fromwidth>80) then
  718.         fromwidth := defaultfromwidth;
  719.     end
  720.   else if tag='size-width' then
  721.     begin
  722.       sizewidth := atoi(avalue);
  723.       usedarg := true;
  724.  
  725.       if (sizewidth<1) or (sizewidth>4) then
  726.         sizewidth := defaultsizewidth;
  727.     end
  728.   else if tag='enter-group-command' then
  729.     begin
  730.       maybesetoptp(tag,entergroupcommand,avalue,mayuserestrictedopts);
  731.       usedarg := true;
  732.     end
  733.   else if tag='dots-on-reset' then
  734.     dotsonreset := bvalue
  735.   else if tag='view-command' then
  736.     begin
  737.       maybesetoptp(tag,viewcommand,avalue,mayuserestrictedopts);
  738.       usedarg := true;
  739.     end
  740.   else if tag='extract-command' then
  741.     begin
  742.       maybesetoptp(tag,extractcommand,avalue,mayuserestrictedopts);
  743.       usedarg := true;
  744.     end
  745.   else if tag='encode-command' then
  746.     begin
  747.       maybesetoptp(tag,encodecommand,avalue,mayuserestrictedopts);
  748.       usedarg := true;
  749.     end
  750.   else if tag='crlf' then
  751.     crlf := bvalue
  752.   else if tag='find-quote-char' then
  753.     findquotechar := bvalue
  754.   else if tag='quote-char' then
  755.     begin
  756.       if length(avalue)>0 then
  757.         quotechar := avalue[1]
  758.       else
  759.         quotechar := '>';
  760.       usedarg := (length(avalue)>0);
  761.     end
  762.   else if tag='print-command' then  {ugh}
  763.     begin
  764.       maybesetoptp(tag,printcommand,avalue,mayuserestrictedopts);
  765.       usedarg := true;
  766.     end
  767.   else if tag='layout' then
  768.     begin
  769.       if avalue='normal' then
  770.         layout := layoutnormal
  771.       else if avalue='squashed' then
  772.         layout := layoutsquashed
  773.       else
  774.         layout := nthlayout(atoi(avalue));
  775.  
  776.       usedarg := true;
  777.     end
  778.   else if (tag='alternate-color') or (tag='alternate-colour') then
  779.     begin
  780.       alternatecolor := colortoi(avalue);
  781.       usedarg := true;
  782.     end
  783.   else if (tag='date-color') or (tag='date-colour') then
  784.     begin
  785.       datecolor := colortoi(avalue);
  786.       usedarg := true;
  787.     end
  788.   else if tag='mail-marker-line' then
  789.     begin
  790.       mailmarkerline := avalue;
  791.       usedarg := (length(avalue)>0);
  792.  
  793.       if trim(mailmarkerline)='' then
  794.         mailmarkerline := defaultmailmarkerline;
  795.     end
  796.   else if tag='news-marker-line' then
  797.     begin
  798.       newsmarkerline := avalue;
  799.       usedarg := (length(avalue)>0);
  800.  
  801.       if trim(newsmarkerline)='' then
  802.         newsmarkerline := defaultnewsmarkerline;
  803.     end
  804.   else if tag='truncate-id-length' then
  805.     begin
  806.       maybesetopti(tag,truncateidlength,atoi(avalue),mayuserestrictedopts);
  807.       usedarg := true;
  808.  
  809.       if truncateidlength<1 then
  810.         truncateidlength := 1;
  811.     end
  812.   else if tag='debug' then
  813.     begin
  814.       debuglist := avalue;
  815.       usedarg := true;
  816.  
  817.       if copy(debuglist,1,1)<>':' then
  818.         debuglist := ':'+debuglist;
  819.       if copy(debuglist,length(debuglist),1)<>':' then
  820.         debuglist := debuglist+':';
  821.     end
  822.   else if tag='date-format' then
  823.     begin
  824.       dateformat := avalue;
  825.       usedarg := true;
  826.     end
  827.   else if tag='mail-date-format' then
  828.     begin
  829.       maildateformat := avalue;
  830.       usedarg := true;
  831.     end
  832.   else if tag='news-date-format' then
  833.     begin
  834.       newsdateformat := avalue;
  835.       usedarg := true;
  836.     end
  837.   else if tag='regex' then
  838.     useregex := bvalue
  839.   else if tag='quote-with-space' then
  840.     quotewithspace := bvalue
  841.   else if tag='find-existing-file-command' then
  842.     begin
  843.       maybesetoptp(tag,findexistingfilecommand,avalue,mayuserestrictedopts);
  844.       usedarg := true;
  845.     end
  846.   else if tag='find-file-command' then
  847.     begin
  848.       maybesetoptp(tag,findfilecommand,avalue,mayuserestrictedopts);
  849.       usedarg := true;
  850.     end
  851.   else if tag='helpful' then
  852.     begin
  853.       helpful := bvalue;
  854.     end
  855.   else if tag='indicate-posted-mail-in-body' then
  856.     begin
  857.       indicatepostedmailinbody := bvalue;
  858.     end
  859.   else if tag='' then
  860.     begin
  861.       warn('set: no arguments found');
  862.     end
  863.   else
  864.     begin
  865.       warn('unknown set option: '+tag);
  866.     end;
  867.  
  868.   handleset := usedarg;
  869. end;
  870.  
  871. procedure justhandleset;
  872.  
  873. var
  874.   wasteboolean: boolean;
  875.  
  876. begin
  877.   wasteboolean := handleset(setline,suspicious);
  878. end;
  879.  
  880. procedure justhandleunset;
  881.  
  882. var
  883.   newsetline: string;
  884.   wasteboolean: boolean;
  885.  
  886. begin
  887.   newsetline := trim(ltrim(setline));
  888.   if pos('=',newsetline)=0 then
  889.     if pos(' ',newsetline)=0 then
  890.       newsetline := newsetline+'=false';
  891.  
  892.   wasteboolean := handleset(newsetline,suspicious);
  893. end;
  894.  
  895. procedure translateuserid;
  896.  
  897. var
  898.   translatefn: string;
  899.   translatef: text;
  900.   translateline: string;
  901.   done: boolean;
  902.  
  903. begin
  904. {waste of time - tpascal doesn't use filemode on text files!}
  905.  
  906.   oldfilemode := filemode;
  907.   if not nofilemode then
  908.     filemode := $40;   {read only, deny none}
  909.  
  910.   translatefn := configdir+'\etc\'+'idtrans';
  911.   safereset(translatef,translatefn);
  912.  
  913.   if showdebug('userid') then
  914.     if fileresult=0 then
  915.       xwritelnss(translatefn,' exists')
  916.     else
  917.       xwritelnss(translatefn,' does not exist');
  918.  
  919.   if fileresult=0 then
  920.     begin
  921.       done := false;
  922.       while not done and not eof(translatef) do
  923.         begin
  924.           readln(translatef,translateline);
  925.  
  926.           if showdebug('userid') then
  927.             xwritelnss('translation line: ',translateline);
  928.  
  929.           if chopfirstw(translateline)=userid then
  930.             begin
  931.               userid := trim(translateline);
  932.               xwritelnssss('using id ',userid,
  933.                ', as per translation file ',translatefn);
  934.               done := true;
  935.             end;
  936.         end;
  937.       close(translatef);
  938.     end;
  939.  
  940.   filemode := oldfilemode;
  941. end;
  942.  
  943. procedure createconfigpathstring(name: configelementname; value: pathstring);
  944.  
  945. var
  946.   aconfigelementptrpathstring: configelementptrpathstring;
  947.  
  948. begin
  949.   if memavail<configmemoryreserved+sizeof(configelementpathstring) then
  950.     msgshutdown('insufficient memory (configuration)',1);
  951.  
  952.   new(aconfigelementptrpathstring);
  953.  
  954.   aconfigelementptrpathstring^.name := name;
  955.   aconfigelementptrpathstring^.value := value;
  956.   aconfigelementptrpathstring^.changed := false;
  957.   aconfigelementptrpathstring^.next := configheadpathstring;
  958.  
  959.   configheadpathstring := aconfigelementptrpathstring;
  960. end;
  961.  
  962. procedure createconfigshortstring(name: configelementname; value: shortstring);
  963.  
  964. var
  965.   aconfigelementptrshortstring: configelementptrshortstring;
  966.  
  967. begin
  968.   if memavail<configmemoryreserved+sizeof(configelementshortstring) then
  969.     msgshutdown('insufficient memory (configuration)',1);
  970.  
  971.   new(aconfigelementptrshortstring);
  972.  
  973.   aconfigelementptrshortstring^.name := name;
  974.   aconfigelementptrshortstring^.value := value;
  975.   aconfigelementptrshortstring^.changed := false;
  976.   aconfigelementptrshortstring^.next := configheadshortstring;
  977.  
  978.   configheadshortstring := aconfigelementptrshortstring;
  979. end;
  980.  
  981. procedure createconfiginteger(name: configelementname; value: integer);
  982.  
  983. var
  984.   aconfigelementptrinteger: configelementptrinteger;
  985.  
  986. begin
  987.   if memavail<configmemoryreserved+sizeof(configelementinteger) then
  988.     msgshutdown('insufficient memory (configuration)',1);
  989.  
  990.   new(aconfigelementptrinteger);
  991.  
  992.   aconfigelementptrinteger^.name := name;
  993.   aconfigelementptrinteger^.value := value;
  994.   aconfigelementptrinteger^.changed := false;
  995.   aconfigelementptrinteger^.next := configheadinteger;
  996.  
  997.   configheadinteger := aconfigelementptrinteger;
  998. end;
  999.  
  1000. procedure createconfigboolean(name: configelementname; value: boolean);
  1001.  
  1002. var
  1003.   aconfigelementptrboolean: configelementptrboolean;
  1004.  
  1005. begin
  1006.   if memavail<configmemoryreserved+sizeof(configelementboolean) then
  1007.     msgshutdown('insufficient memory (configuration)',1);
  1008.  
  1009.   new(aconfigelementptrboolean);
  1010.  
  1011.   aconfigelementptrboolean^.name := name;
  1012.   aconfigelementptrboolean^.value := value;
  1013.   aconfigelementptrboolean^.changed := false;
  1014.   aconfigelementptrboolean^.next := configheadboolean;
  1015.  
  1016.   configheadboolean := aconfigelementptrboolean;
  1017. end;
  1018.  
  1019. procedure createallconfigspathstring;
  1020.  
  1021. begin
  1022.   configheadpathstring := nil;
  1023.   savedconfigheadpathstring := nil;
  1024.  
  1025.   createconfigpathstring('name','value');
  1026. end;
  1027.  
  1028. procedure createallconfigsshortstring;
  1029.  
  1030. begin
  1031.   configheadshortstring := nil;
  1032.   savedconfigheadshortstring := nil;
  1033.  
  1034.   createconfigshortstring('name','value');
  1035. end;
  1036.  
  1037. procedure createallconfigsinteger;
  1038.  
  1039. begin
  1040.   configheadinteger := nil;
  1041.   savedconfigheadinteger := nil;
  1042.  
  1043.   createconfiginteger('name',0);
  1044. end;
  1045.  
  1046. procedure createallconfigsboolean;
  1047.  
  1048. begin
  1049.   configheadboolean := nil;
  1050.   savedconfigheadboolean := nil;
  1051.  
  1052.   createconfigboolean('name',false);
  1053. end;
  1054.  
  1055. procedure initialize;
  1056.  
  1057. var
  1058.   currparmi: integer;
  1059.   currparm: string;
  1060.   nextparm: string;
  1061.   rcf: text;
  1062.   rctag: string;
  1063.   rcval: string;
  1064.   wantedtogotosource: boolean;
  1065.   ch: char;
  1066.  
  1067. procedure initopts;
  1068.  
  1069. begin
  1070.   foundtrusted := false;
  1071.  
  1072. {}{}{ should be based on cols when known }
  1073.   defaultfromwidth := 20;
  1074.   defaultsizewidth := 3;  {max 1-byte non-negative integer is 3 digits}
  1075.  
  1076.   userid := '';
  1077.   currsource := '';
  1078.   currdir := '';
  1079.   currsourcekind := sourcegroup;
  1080.   forumsetl := '';
  1081.   iface := '';
  1082.   xiface := ifaceunknown;
  1083.   ifaceversion := '';
  1084.   uupcusr := '';
  1085.   uupcsys := '';
  1086.   timezone := '';
  1087.  
  1088.   maildateformat := 'www, mmm dd';
  1089.   newsdateformat := 'mmm dd';
  1090.   dateformat := '(!error)';
  1091.  
  1092.   useregex := false;
  1093.   quotewithspace := false;
  1094.  
  1095.   findexistingfilecommand := builtincookie;
  1096.   findfilecommand := builtincookie;
  1097.  
  1098.   helpful := false;
  1099.   indicatepostedmailinbody := false;
  1100.  
  1101. {$ifdef tiny}
  1102.   console := false;
  1103.   port := 0;
  1104.   trusted := false;
  1105.   minutestorun := 60;
  1106. {$else}
  1107.   console := true;
  1108.   port := -1;
  1109.   trusted := true;
  1110.   minutestorun := maxint;
  1111. {$endif}
  1112.  
  1113.   fullname := '';
  1114.   editor := '';
  1115.   editoroptions := '';
  1116.   vspeller := '';
  1117.   vspelleroptions := '';
  1118.   shadow := 0;
  1119.   rcfilename := '';
  1120.  
  1121.   netmail := '';
  1122.   netnews := '';
  1123.   replyto := '';
  1124.  
  1125.   subjectscaseinsensitive := false;
  1126.   subjectlength := 50;
  1127.   squashspaces := false;
  1128.   equatetruncated := 0;
  1129.   makespacelikex := false;
  1130.   hideheaders := '';
  1131.   showheaders := '';
  1132.   highlightheaders := upper(':Subject:From:Date:');
  1133.   nomailfrom := false;
  1134.   nomailheaders := '';
  1135.   nonewsheaders := '';
  1136.   wanderingnumbers := false;
  1137.   antikillreferences := false;
  1138.   showsubjectkills := false;
  1139.   showfromkills := false;
  1140.   showsubjectantikills := false;
  1141.   showfromantikills := false;
  1142.   showkills := false;
  1143.   showantikills := false;
  1144.   autoantikill := false;
  1145.   warnautoantikill := false;
  1146.   editaftervspell := false;
  1147.   caseinsensitivekill := false;
  1148.   caseinsensitiveantikill := false;
  1149.   substringsubjectkill := false;
  1150.   substringfromkill := false;
  1151.   substringsubjectantikill := false;
  1152.   substringfromantikill := false;
  1153.   quiet := false;
  1154.   ignoreenvironment := false;
  1155.   confirmquit := false;
  1156.   confirmnextgroup := false;
  1157.   confirmnextarticle := false;
  1158.   missingsubjectisok := false;
  1159.   tildehome := true;
  1160.   antikillthisnewsreader := false;
  1161.   clearscreenbetweengroups := false;
  1162.   detectvideo := true;
  1163.   antikillevenkilled := false;
  1164.   mailprefix := '';
  1165.   ignoremouse := false;
  1166.   usebiosforscreen := false;
  1167.   hideformfeeds := false;
  1168.   pathuserid := '';
  1169.   fromuserid := '';
  1170.   customstatic := '';
  1171.   haltonunknowngroups := false;
  1172.   mousecharsheader := '< > ^ $ * - + Q N @ ~ Z G ''';
  1173.   justdots := false;
  1174.   nofilemode := false;
  1175.   quitmessage := 'Closing files...';
  1176.   outputseparator := '---cut-here---';
  1177.   newscmdline := '';
  1178.   mailcmdline := '';
  1179.   mailagent := false;
  1180.   outgoingmail := '';
  1181.   outgoingnews := 'monitor';
  1182.   highlightsearchhits := false;
  1183.   colors := '';
  1184.   quotecolor := 255;
  1185.  
  1186. {$ifdef charset}
  1187.   uselocalcharset := false;
  1188.   localcharsetfn := '';
  1189. {$endif}
  1190.  
  1191.   rmailsingle := false;
  1192.  
  1193.   idleminutes := 0;
  1194.  
  1195.   if (dosversion and $ff)<3 then
  1196.     swap := 'disk'
  1197.   else
  1198.     swap := 'ems';
  1199.  
  1200.   articlefilenamepattern := '*';
  1201.   overviewbasename := 'overview';
  1202.  
  1203.   fromwidth := defaultfromwidth;
  1204.   sizewidth := defaultsizewidth;
  1205.  
  1206.   entergroupcommand := '';
  1207.  
  1208.   dotsonreset := false;
  1209.  
  1210.   viewcommand := 'viewart';
  1211.   extractcommand := 'munpack';
  1212.   encodecommand := 'encode';
  1213.  
  1214.   crlf := true;  {used to default to false before we had unset}
  1215.   findquotechar := false;
  1216.  
  1217.   printcommand := 'paginate';  {ugh}
  1218.  
  1219.   netware := false;
  1220.  
  1221.   layout := layoutnormal;
  1222.  
  1223.   alternatecolor := 255;
  1224.   datecolor := 255;
  1225.  
  1226.   mailmarkerline := defaultmailmarkerline;
  1227.   newsmarkerline := defaultnewsmarkerline;
  1228.   truncateidlength := 8;
  1229.  
  1230.   debuglist := '';
  1231.  
  1232.   if (dosversion and $ff)<3 then
  1233.     nofilemode := true;
  1234.  
  1235.   configdir := '';
  1236.  
  1237.   browseuppersearchstring := '';
  1238. end;
  1239.  
  1240. function handleoption(tag, maybedash: string; suspicious: boolean): boolean;
  1241.  
  1242. {tag must be lower-case}
  1243.  
  1244. var
  1245.   avalue: string;
  1246.   usedarg: boolean;
  1247.   mayuserestrictedopts: boolean;
  1248.   handleviaset: boolean;
  1249.  
  1250. begin {handleoption}
  1251.  
  1252.   handleviaset := false;
  1253.  
  1254.   if maybedash='-' then
  1255.     avalue := ''
  1256.   else
  1257.     avalue := maybedash;
  1258.  
  1259.   usedarg := false;
  1260.  
  1261. {$ifdef trustedusersmayputrestrictedoptsinuserrcfile}
  1262.   mayuserestrictedopts := trusted or (not suspicious);
  1263. {$else}
  1264.   mayuserestrictedopts := not suspicious;
  1265. {$endif}
  1266.  
  1267.   if (tag='-?') or (tag='--help') then
  1268.     usage
  1269.   else if tag='--map' then
  1270.     begin
  1271.       handlemap(avalue);
  1272.       usedarg := true;
  1273.     end
  1274.   else if (tag='-u') or (tag='--user') then
  1275.     begin
  1276.       if showdebug('userid') then
  1277.         xwritelnss('with -u/--user, attempting to set userid to ',avalue);
  1278.       maybesetoptsh(tag,userid,avalue,mayuserestrictedopts);
  1279.       usedarg := true;
  1280.     end
  1281.   else if (tag='-n') or (tag='--newsgroup') then
  1282.     begin
  1283.       currsource := avalue;
  1284.       currsourcekind := sourcegroup;
  1285.       if currsource<>'' then
  1286.         needtofindnextgroup := false;
  1287.       usedarg := true;
  1288.     end
  1289.   else if (tag='-g') or (tag='--goto') then
  1290.     begin
  1291.       wantedtogotosource := true;
  1292.       if copy(avalue,1,1)<>'-' then
  1293.         begin
  1294.           currsource := avalue;
  1295.           currsourcekind := sourcegroup;
  1296.           usedarg := true;
  1297.         end;
  1298.     end
  1299.   else if (tag='-p') or (tag='--port') then
  1300.     begin
  1301.       maybesetopti(tag,port,atoi(avalue)-1,mayuserestrictedopts);
  1302.       console := false;
  1303.       trusted := false;
  1304.       usedarg := true;
  1305.     end
  1306.   else if (tag='-l') or (tag='--lines') then
  1307.     begin
  1308.       lpp := atoi(avalue);
  1309.       usedarg := true;
  1310.     end
  1311.   else if (tag='-c') or (tag='--columns') then
  1312.     begin
  1313.       cols := atoi(avalue);
  1314.       usedarg := true;
  1315.     end
  1316.   else if (tag='-f') or (tag='--fullname') then
  1317.     begin
  1318.       maybesetopts(tag,fullname,
  1319.        trim(ununderscore(avalue)),mayuserestrictedopts);
  1320.       usedarg := true;
  1321.     end
  1322.   else if (tag='-e') or (tag='--editor') then
  1323.     handleviaset := true
  1324.   else if (tag='-o') or (tag='--editor-options') then
  1325.     handleviaset := true
  1326.   else if (tag='-s') or (tag='--forum-set-list') then
  1327.     begin
  1328.       maybesetopts(tag,forumsetl,
  1329.        uncomma(ununderscore(avalue)),mayuserestrictedopts);
  1330.       usedarg := true;
  1331.     end
  1332.   else if (tag='-t') or (tag='--trusted') then
  1333.     begin
  1334.       maybesetoptb(tag,foundtrusted,true,mayuserestrictedopts);
  1335.     end
  1336.   else if tag='--waffle-version' then
  1337.     begin
  1338.       maybesetoptsh(tag,ifaceversion,avalue,mayuserestrictedopts);
  1339.       usedarg := true;
  1340.  
  1341.       xwritelns(
  1342.        'warning: obsolete option --waffle-version - use --interface-version');
  1343.     end
  1344.   else if (tag='-v') or (tag='--interface-version') then
  1345.     begin
  1346.       maybesetoptsh(tag,ifaceversion,avalue,mayuserestrictedopts);
  1347.       usedarg := true;
  1348.     end
  1349.   else if (tag='-m') or (tag='--minutes') then
  1350.     begin
  1351.       maybesetopti(tag,minutestorun,atoi(avalue),mayuserestrictedopts);
  1352.       usedarg := true;
  1353.     end
  1354.   else if (tag='-d') or (tag='--shadow') then
  1355.     handleviaset := true
  1356.   else if (tag='-r') or (tag='--rcfile') then
  1357.     begin
  1358.       maybesetoptp(tag,rcfilename,unslash(avalue),mayuserestrictedopts);
  1359.       usedarg := true;
  1360.     end
  1361.   else if (tag='-i') or (tag='--interface') then
  1362.     begin
  1363.       maybesetoptsh(tag,iface,avalue,mayuserestrictedopts);
  1364.       usedarg := true;
  1365.     end
  1366.   else if tag='--console' then
  1367.     begin
  1368.       if mayuserestrictedopts then
  1369.         begin
  1370.           console := true;
  1371.           port := -1;
  1372.           trusted := true;
  1373.           minutestorun := maxint;
  1374.         end;
  1375.       xwritelns('warning: obsolete option --console');
  1376.     end
  1377.   else if tag='--vspeller' then
  1378.     handleviaset := true
  1379.   else if tag='--vspeller-options' then
  1380.     handleviaset := true
  1381.   else if tag='--set' then
  1382.     begin
  1383.       justhandleset(avalue,suspicious);
  1384.       usedarg := true;
  1385.     end
  1386.   else if tag='--unset' then
  1387.     begin
  1388.       justhandleunset(avalue,suspicious);
  1389.       usedarg := true;
  1390.     end
  1391.   else if tag='--subjects-case-insensitive' then
  1392.     handleviaset := true
  1393.   else if tag='--subject-length' then
  1394.     handleviaset := true
  1395.   else if tag='--squash-spaces' then
  1396.     handleviaset := true
  1397.   else if tag='--equate-truncated' then
  1398.     handleviaset := true
  1399.   else if tag='--make-space-like-x' then
  1400.     handleviaset := true
  1401.   else if tag='--make-return-like-asterisk' then
  1402.     begin
  1403.       xwritelns('warning: obsolete option --make-return-like-asterisk');
  1404.       xwritelns('warning: use --select =13 * instead');
  1405.       handlemap('select =13 *');
  1406.     end
  1407.   else if tag='--hide-these-headers' then
  1408.     handleviaset := true
  1409.   else if tag='--show-only-these-headers' then
  1410.     handleviaset := true
  1411.   else if tag='--highlight-these-headers' then
  1412.     handleviaset := true
  1413.   else if tag='--no-mail-from' then
  1414.     handleviaset := true
  1415.   else if tag='--no-mail-headers' then
  1416.     handleviaset := true
  1417.   else if tag='--no-news-headers' then
  1418.     handleviaset := true
  1419.   else if tag='--wandering-numbers' then
  1420.     handleviaset := true
  1421.   else if tag='--antikill-references' then
  1422.     handleviaset := true
  1423.   else if tag='--show-subject-kills' then
  1424.     handleviaset := true
  1425.   else if tag='--show-from-kills' then
  1426.     handleviaset := true
  1427.   else if tag='--show-subject-antikills' then
  1428.     handleviaset := true
  1429.   else if tag='--show-from-antikills' then
  1430.     handleviaset := true
  1431.   else if tag='--show-kills' then
  1432.     handleviaset := true
  1433.   else if tag='--show-antikills' then
  1434.     handleviaset := true
  1435.   else if tag='--auto-antikill' then
  1436.     handleviaset := true
  1437.   else if tag='--warn-auto-antikill' then
  1438.     handleviaset := true
  1439.   else if tag='--edit-after-vspell' then
  1440.     handleviaset := true
  1441.   else if tag='--case-insensitive-kill' then
  1442.     handleviaset := true
  1443.   else if tag='--case-insensitive-antikill' then
  1444.     handleviaset := true
  1445.   else if tag='--substring-subject-kill' then
  1446.     handleviaset := true
  1447.   else if tag='--substring-from-kill' then
  1448.     handleviaset := true
  1449.   else if tag='--substring-subject-antikill' then
  1450.     handleviaset := true
  1451.   else if tag='--substring-from-antikill' then
  1452.     handleviaset := true
  1453.   else if tag='--quiet' then
  1454.     handleviaset := true
  1455.   else if tag='--ignore-environment' then
  1456.     maybesetoptb(tag,ignoreenvironment,true,mayuserestrictedopts)
  1457.   else if tag='--confirm-quit' then
  1458.     handleviaset := true
  1459.   else if tag='--confirm-next' then  {}{}{}{backwards-compatible}
  1460.     handleviaset := true
  1461.   else if tag='--confirm-next-group' then
  1462.     handleviaset := true
  1463.   else if tag='--confirm-next-article' then
  1464.     handleviaset := true
  1465.   else if tag='--missing-subject-is-ok' then
  1466.     handleviaset := true
  1467.   else if tag='--tilde-home' then
  1468.     handleviaset := true
  1469.   else if tag='--antikill-this-newsreader' then
  1470.     handleviaset := true
  1471.   else if tag='--clear-screen-between-groups' then
  1472.     handleviaset := true
  1473.   else if tag='--detect-video' then
  1474.     handleviaset := true
  1475.   else if tag='--antikill-even-killed' then
  1476.     handleviaset := true
  1477.   else if tag='--mail-prefix' then
  1478.     begin
  1479.       maybesetoptp(tag,mailprefix,avalue,mayuserestrictedopts);
  1480.       usedarg := true;
  1481.     end
  1482.   else if tag='--ignore-mouse' then
  1483.     ignoremouse := true
  1484.   else if tag='--use-bios-for-screen' then
  1485.     handleviaset := true
  1486.   else if tag='--hide-form-feeds' then
  1487.     handleviaset := true
  1488.   else if tag='--path-userid' then
  1489.     handleviaset := true
  1490.   else if tag='--from-userid' then
  1491.     handleviaset := true
  1492.   else if tag='--custom-static' then
  1493.     handleviaset := true
  1494.   else if tag='--halt-on-unknown-groups' then
  1495.     handleviaset := true
  1496.   else if tag='--mouse-chars-header' then
  1497.     handleviaset := true
  1498.   else if tag='--just-dots' then
  1499.     handleviaset := true
  1500.   else if tag='--no-filemode' then
  1501.     handleviaset := true
  1502.   else if tag='--quit-message' then
  1503.     handleviaset := true
  1504.   else if tag='--output-separator' then
  1505.     handleviaset := true
  1506.   else if tag='--news-cmd-line' then
  1507.     handleviaset := true
  1508.   else if tag='--mail-cmd-line' then
  1509.     handleviaset := true
  1510.   else if tag='--mail-agent' then
  1511.     handleviaset := true
  1512.   else if tag='--outgoing-mail' then
  1513.     handleviaset := true
  1514.   else if tag='--outgoing-news' then
  1515.     handleviaset := true
  1516.   else if tag='--highlight-search-hits' then
  1517.     handleviaset := true
  1518.   else if (tag='--colors') or (tag='--colours') then
  1519.     handleviaset := true
  1520.   else if (tag='--quote-color') or (tag='--quote-color') then
  1521.     handleviaset := true
  1522.  
  1523. {$ifdef charset}
  1524.   else if tag='--local-charset' then
  1525.     handleviaset := true
  1526. {$endif}
  1527.  
  1528.   else if tag='--rmail-single' then
  1529.     handleviaset := true
  1530.   else if tag='--idle' then
  1531.     handleviaset := true
  1532.   else if tag='--swap' then
  1533.     handleviaset := true
  1534.   else if tag='--article-filename-pattern' then
  1535.     handleviaset := true
  1536.   else if tag='--overview-base-name' then
  1537.     handleviaset := true
  1538.   else if tag='--from-width' then
  1539.     handleviaset := true
  1540.   else if tag='--size-width' then
  1541.     handleviaset := true
  1542.   else if tag='--enter-group-command' then
  1543.     handleviaset := true
  1544.   else if tag='--dots-on-reset' then
  1545.     handleviaset := true
  1546.   else if tag='--view-command' then
  1547.     handleviaset := true
  1548.   else if tag='--extract-command' then
  1549.     handleviaset := true
  1550.   else if tag='--encode-command' then
  1551.     handleviaset := true
  1552.   else if tag='--crlf' then
  1553.     handleviaset := true
  1554.   else if tag='--find-quote-char' then
  1555.     handleviaset := true
  1556.   else if tag='--print-command' then  {ugh}
  1557.     handleviaset := true
  1558.   else if tag='--netware' then
  1559.     maybesetoptb(tag,netware,true,mayuserestrictedopts)
  1560.   else if tag='--layout' then
  1561.     handleviaset := true
  1562.   else if (tag='--alternate-color') or (tag='--alternate-colour') then
  1563.     handleviaset := true
  1564.   else if (tag='--date-color') or (tag='--date-colour') then
  1565.     handleviaset := true
  1566.   else if tag='--mail-from' then
  1567.     begin
  1568.       maybesetopts(tag,netmail,avalue,mayuserestrictedopts);  {verified later}
  1569.       usedarg := true;
  1570.     end
  1571.   else if tag='--news-from' then
  1572.     begin
  1573.       maybesetopts(tag,netnews,avalue,mayuserestrictedopts);  {verified later}
  1574.       usedarg := true;
  1575.     end
  1576.   else if tag='--reply-to' then
  1577.     begin
  1578.       maybesetopts(tag,replyto,avalue,mayuserestrictedopts);  {verified later}
  1579.       usedarg := true;
  1580.     end
  1581.   else if tag='--mail-marker-line' then
  1582.     handleviaset := true
  1583.   else if tag='--news-marker-line' then
  1584.     handleviaset := true
  1585.   else if tag='--truncate-id-length' then
  1586.     handleviaset := true
  1587.   else if tag='--debug' then
  1588.     handleviaset := true
  1589.   else if tag='--mail-date-format' then
  1590.     handleviaset := true
  1591.   else if tag='--news-date-format' then
  1592.     handleviaset := true
  1593.   else if tag='--regex' then
  1594.     handleviaset := true
  1595.   else if tag='--quote-with-space' then
  1596.     handleviaset := true
  1597.   else if tag='--find-file-command' then
  1598.     handleviaset := true
  1599.   else
  1600.     begin
  1601.  
  1602.  
  1603. {$ifdef ignoreoldoptions}
  1604.  
  1605. { compatibility switch with earlier releases - now obsolete }
  1606.  
  1607. {try to make sure any error messages are going to be visible!}
  1608.  
  1609.       console := true;
  1610.       xwritesss(newsreadername,' ',newsreaderversion);
  1611.       xwritelnss(': unknown option: ',tag);
  1612.       usage;  {usage shuts down}
  1613.  
  1614. {$else}
  1615.  
  1616.       userid := tag;
  1617.       xwritelns('warning: obsolete usage of userid on the command line');
  1618.       xwritelns('use -u/--user instead');
  1619.  
  1620. {$endif}
  1621.  
  1622.     end;
  1623.  
  1624.   if handleviaset then
  1625.     usedarg := handleset(tag+' '+avalue,suspicious);
  1626.  
  1627.   if foundtrusted then
  1628.     trusted := true;
  1629.  
  1630.   handleoption := usedarg;
  1631.  
  1632. end; {handleoption}
  1633.  
  1634. begin {initialize}
  1635.  
  1636. {$ifdef timeout}
  1637.  
  1638. { need to do this now, in case anything is illegal and needs a warn() }
  1639.   minstart := mitoday;
  1640.   minlastinput := mitoday;
  1641.  
  1642. {$endif}
  1643.  
  1644.  
  1645. {set up things for clean shutdowns}
  1646.  
  1647.   oldtextattr := textattr;
  1648.  
  1649.   haskillfile := false;
  1650.   hasantikillfile := false;
  1651.  
  1652. {
  1653.   killfileinmem := false;
  1654.   antikillfileinmem := false;
  1655. }
  1656.  
  1657.   joinfn := '';
  1658.  
  1659. {$ifdef mouse}
  1660.  
  1661.   hasmouse := false;
  1662.  
  1663. {$endif}
  1664.  
  1665.  
  1666.  
  1667.   randomize;
  1668.  
  1669. {
  1670.   if memavail<configmemoryreserved+
  1671.    sizeof(filenamesp^)+
  1672.    sizeof(fromsp^)+
  1673.    sizeof(datesp^) then
  1674.     msgshutdown('insufficient memory',1);
  1675.  
  1676.   new(filenamesp);
  1677.   new(fromsp);
  1678.   new(datesp);
  1679. }
  1680.  
  1681.   if memavail<configmemoryreserved+
  1682.    sizeof(groupkillsp^)+
  1683.    sizeof(killsp^) then
  1684.     msgshutdown('insufficient memory (kill)',1);
  1685.  
  1686.   new(groupkillsp);
  1687.   new(killsp);
  1688.  
  1689.   if memavail<configmemoryreserved+
  1690.    sizeof(groupantikillsp^)+
  1691.    sizeof(antikillsp^) then
  1692.     msgshutdown('insufficient memory (antikill)',1);
  1693.  
  1694.   new(groupantikillsp);
  1695.   new(antikillsp);
  1696.  
  1697. {
  1698.   if memavail<configmemoryreserved+sizeof(hmessageidsp^) then
  1699.     msgshutdown('insufficient memory (messageid)',1);
  1700.  
  1701.   new(hmessageidsp);
  1702.  
  1703.   if memavail<configmemoryreserved+numhashedrefs*sizeof(hreferencesp[1]^) then
  1704.     msgshutdown('insufficient memory (references)',1);
  1705.  
  1706.   new(hreferencesp[1]);
  1707.   new(hreferencesp[2]);
  1708.   new(hreferencesp[3]);
  1709.   new(hreferencesp[4]);
  1710. }
  1711.  
  1712.   createallconfigspathstring;
  1713.   createallconfigsshortstring;
  1714.   createallconfigsinteger;
  1715.   createallconfigsboolean;
  1716.  
  1717.   allocatedarts := 0;
  1718.   while (memavail>configmemoryreserved+sizeof(articles[1]^)) and
  1719.    (allocatedarts<maxarts) do
  1720.     begin
  1721.       inc(allocatedarts);
  1722.       new(articles[allocatedarts]);
  1723.     end;
  1724.  
  1725.   if allocatedarts<2 then
  1726.     msgshutdown('insufficient memory -- cannot hold even 2 articles!',1);
  1727.  
  1728.   initopts;
  1729.  
  1730.   needtofindnextgroup := true;
  1731.   lowestartsearched := impossiblylargeart;
  1732.   readpagesback := 0;
  1733.   readunfiltered := false;
  1734.   antikilledonly := false;
  1735.   searchinheaders := false;
  1736.   searchinbody := false;
  1737.   searchthedate := false;
  1738.   searchinsubj := false;
  1739.   searchinname := false;
  1740.   searchtext := '';
  1741.   searchdatelow := ymdtodate(currentdatestring);
  1742.   searchdatehigh := ymdtodate(currentdatestring);
  1743.  
  1744.   wantedtogotosource := false;
  1745.  
  1746.   lastfilen := '';
  1747.   lastfolder := '';
  1748.  
  1749.   defaultlppcols;
  1750.  
  1751.   for ch := chr(0) to chr(255) do
  1752.     begin
  1753.       browsemap[ch] := ch;
  1754.       selmap[ch] := ch;
  1755.       mainmap[ch] := ch;
  1756.     end;
  1757.  
  1758. {first do command-line options, which may use restricted options}
  1759.  
  1760. {$ifdef debug}
  1761.   xwritelns('parameters:');
  1762.   for currparmi := 1 to paramcount do
  1763.     xwritelns(paramstr(currparmi));
  1764. {$endif}
  1765.  
  1766.   currparmi := 1;
  1767.   while currparmi<=paramcount do
  1768.     begin
  1769.       currparm := paramstr(currparmi);
  1770.       if currparmi<paramcount then
  1771.         nextparm := paramstr(currparmi+1)
  1772.       else
  1773.         nextparm := '';
  1774.  
  1775. {not suspicious because it's on the command-line}
  1776.       if handleoption(lower(currparm),nextparm,notsuspicious) then
  1777.         inc(currparmi);
  1778.  
  1779.       inc(currparmi);
  1780.  
  1781.     end;
  1782.  
  1783. {then do rcfile options, which may also use restricted options}
  1784.  
  1785.   if rcfilename<>'' then
  1786.     begin
  1787.  
  1788. {waste of time - tpascal doesn't use filemode on text files!}
  1789.  
  1790.       oldfilemode := filemode;
  1791.       if not nofilemode then
  1792.         filemode := $40;   {read only, deny none}
  1793.  
  1794.       safereset(rcf,rcfilename);
  1795.       if fileresult<>0 then
  1796.         begin
  1797.           console := true;
  1798.           xwritelnss('could not open rc file ',rcfilename);
  1799.           shutdown(1);
  1800.         end;
  1801.  
  1802. {reset it for next time around}
  1803.       rcfilename := '';
  1804.       while not eof(rcf) do
  1805.         begin
  1806.           readln(rcf,rcval);
  1807.           rctag := chopfirstw(rcval);
  1808.           if length(rctag)>0 then
  1809.             if rctag[1]<>'#' then
  1810.               begin
  1811.                 if rctag[1]<>'-' then
  1812.                   rctag := '--'+rctag;
  1813.  
  1814. {not suspicious because it's in the rc file specified on the command-line}
  1815.                 if handleoption(lower(rctag),rcval,notsuspicious) then
  1816.                   ;
  1817.               end;
  1818.         end;
  1819.       close(rcf);
  1820.  
  1821.       filemode := oldfilemode;
  1822.  
  1823.       if rcfilename<>'' then
  1824.         xwritelns('cannot use -r/--rcfile inside an rcfile, sorry');
  1825.     end;
  1826.  
  1827.   if usebiosforscreen then
  1828.     directvideo := false;
  1829.  
  1830. {try to make sure any error messages are going to be visible!}
  1831.  
  1832.   if not console and (port<>0) and (port<>1) and (port<>2) and (port<>3) then
  1833.     begin
  1834.       console := true;
  1835.       xwritelns('error: -p/--port specified without valid port number');
  1836.       xwritelns('  valid numbers are 1 (COM1) and 2 (COM2)   (3=COM3 and');
  1837.       xwritelns('  4=COM4 allowed, your fossil may not support them)');
  1838.       shutdown(1);
  1839.     end;
  1840.  
  1841.   xwritelnsss(newsreadername,' ',newsreaderversion);
  1842.  
  1843.   wafenv := unslash(getenv('WAFFLE'));
  1844.   uupcusr := unslash(getenv('UUPCUSRRC'));
  1845.   uupcsys := unslash(getenv('UUPCSYSRC'));
  1846.  
  1847.   if (iface='') and (wafenv<>'') then
  1848.     begin
  1849.       iface := 'waffle';
  1850.       notquietlns('(assuming waffle interface)');
  1851.     end;
  1852.  
  1853.   if (iface='') and (uupcusr<>'') then
  1854.     begin
  1855.       iface := 'uupc';
  1856.       notquietlns('(assuming uupc interface)');
  1857.     end;
  1858.  
  1859.   if iface='waffle' then
  1860.     xiface := ifacewaffle
  1861.   else if iface='uupc' then
  1862.     xiface := ifaceuupc
  1863.   else if iface='uufree' then
  1864.     xiface := ifaceuufree
  1865.   else
  1866.     begin
  1867.       xwritelnss('unknown interface: ',iface);
  1868.       xwritelns('currently known:  waffle, uupc, uufree');
  1869.       shutdown(1);
  1870.     end;
  1871.  
  1872.  
  1873.   if userid='' then
  1874.     if showdebug('userid') then
  1875.       begin
  1876.         if ignoreenvironment then
  1877.           xwritelns('will ignore these environment variables:');
  1878.         xwritelnss('NET_NAME=',getenv('NET_NAME'));
  1879.         xwritelnss('USER=',getenv('USER'));
  1880.         xwritelnss('LOGNAME=',getenv('LOGNAME'));
  1881.         xwritelnss('USERNAME=',getenv('USERNAME'));
  1882.       end;
  1883.  
  1884.   if (userid='') and not ignoreenvironment then
  1885.     userid := getenv('NET_NAME');
  1886.   if (userid='') and not ignoreenvironment then
  1887.     userid := getenv('USER');
  1888.   if (userid='') and not ignoreenvironment then
  1889.     userid := getenv('LOGNAME');
  1890.   if (userid='') and not ignoreenvironment then
  1891.     userid := getenv('USERNAME');
  1892.  
  1893.  
  1894.   if userid='' then
  1895.     if showdebug('userid') then
  1896.       xwritelnss('getconfig(mailbox) returns: ',getconfig('mailbox'));
  1897.  
  1898.   if userid='' then
  1899.     userid := getconfig('mailbox');
  1900.  
  1901.  
  1902.   if (userid='') and netware then
  1903.     if showdebug('userid') then
  1904.       xwritelnss('getnetwareid returns: ',getnetwareid);
  1905.  
  1906.   if (userid='') and netware then
  1907.     userid := getnetwareid;
  1908.  
  1909.  
  1910.   if userid='' then
  1911.     begin
  1912.       xwritelns('unable to determine userid');
  1913.       usage;
  1914.     end;
  1915.  
  1916.   if showdebug('userid') then
  1917.     if length(userid)>truncateidlength then
  1918.       xwritelns('truncating userid');
  1919.  
  1920.   userid := lower(copy(userid,1,truncateidlength));
  1921.   xwritelnss('user: ',userid);
  1922.  
  1923.   if (xiface=ifacewaffle) and (wafenv='') then
  1924.     begin
  1925. {$ifdef waffleenvcanbemissing}
  1926.       xwritelns('no WAFFLE environment variable - using `./static''.');
  1927.       wafenv := './static';
  1928. {$else}
  1929.       xwritelns('must set WAFFLE environment variable');
  1930.       shutdown(1);
  1931. {$endif}
  1932.     end;
  1933.  
  1934.   if (xiface=ifaceuupc) and (uupcsys='') then
  1935.     begin
  1936.       xwritelns('must set UUPCSYSRC environment variable');
  1937.       shutdown(1);
  1938.     end;
  1939.  
  1940.   if (xiface=ifaceuufree) and (wafenv='') then
  1941.     begin
  1942. {$ifdef waffleenvcanbemissing}
  1943.       xwritelns('no WAFFLE environment variable - using `./static''.');
  1944.       wafenv := './static';
  1945. {$else}
  1946.       xwritelns('must set WAFFLE environment variable');
  1947.       shutdown(1);
  1948. {$endif}
  1949.     end;
  1950.  
  1951.   if (ifaceversion='') and not ignoreenvironment then
  1952.     ifaceversion := getenv('INTERFACEVERSION');
  1953.  
  1954.   if (ifaceversion='') and (xiface=ifacewaffle) and not ignoreenvironment then
  1955.     ifaceversion := getenv('WAFFLEVERSION');
  1956.  
  1957. {
  1958. need to define configdir before using it to check if waf165's index
  1959. file is there for 1.65 auto-detection
  1960. }
  1961.  
  1962.   configdir := getconfig('configdir');
  1963.   if (configdir='') and (xiface=ifacewaffle) then
  1964.     configdir := copy(wafenv,1,rposc(wafenv,'\')-1);
  1965.   if (configdir='') and (xiface=ifaceuufree) then
  1966.     configdir := copy(wafenv,1,rposc(wafenv,'\')-1);
  1967.   configdir := unslash(configdir);
  1968.  
  1969.   if ifaceversion='' then
  1970.     ifaceversion := getconfig('version');
  1971.  
  1972.   if (ifaceversion='') and (xiface=ifacewaffle) then
  1973.     if fexists(configdir+'\admin\'+'index') then
  1974.       ifaceversion := '1.65'
  1975.     else
  1976.       ifaceversion := '1.64';
  1977.  
  1978.   if (ifaceversion='') and (xiface=ifaceuufree) then
  1979.     ifaceversion := ifaceversionunix;
  1980.  
  1981.   if xiface=ifacewaffle then
  1982.     if ifaceversion<>ifaceversionunix then
  1983.       if (length(ifaceversion)<>4) or (copy(ifaceversion,2,1)<>'.') or
  1984.        (numoccur('.',ifaceversion)<>1) then
  1985.         begin
  1986.           xwritelns('WAFFLEVERSION environment variable, or static file');
  1987.           xwritelns('version: setting, or -v/--interface-version argument');
  1988.           xwritelns('in wrong format -- should be either `unix'' or a');
  1989.           xwritelns('number similar to `1.64'' (without the quotes)');
  1990.           xwritelnsss('it is currently set to: `',ifaceversion,'''');
  1991.           shutdown(1);
  1992.         end;
  1993.  
  1994.   if not quiet then
  1995.     begin
  1996.       xwritess('interface: ',iface);
  1997.       xwritelnss(', version ',ifaceversion);
  1998.     end;
  1999.  
  2000. { not that useful -- only shows what's left inside pre-allocated heap }
  2001.  
  2002. {
  2003.   notquietlns(ltoa(memavail div 1024)+'k available');
  2004. }
  2005.  
  2006.   if allocatedarts<maxarts then
  2007.     xwritelns('maximum '+itoa(allocatedarts)+' articles');
  2008.  
  2009.   if debuglist<>'' then
  2010.     notquietlnss('debug: ',debuglist);
  2011.  
  2012.   temporarydir := getconfig('tempdir');
  2013.  
  2014.   if not ignoreenvironment then
  2015.     begin
  2016.       temporarydir := default(getenv('TMP'),temporarydir);
  2017.       temporarydir := default(getenv('TEMP'),temporarydir);
  2018.     end;
  2019.   temporarydir := default('.',temporarydir);
  2020.   temporarydir := unslash(temporarydir);
  2021.  
  2022.   spooldir := unslash(default(configdir+'/spool',getconfig('spooldir')));
  2023.   userdir := unslash(default(configdir+'/user',getconfig('userdir')));
  2024.   outboxdir := unslash(default(spooldir+'/outbox',getconfig('outboxdir')));
  2025.   outform := default('flat',lower(getconfig('outform')));
  2026.  
  2027. {outform hierarchy will be in waffle 1.66}
  2028.   if (outform<>'flat') and (outform<>'hierarchy') then
  2029.     begin
  2030.       xwritelnsss('unsupported outbox format: ',outform,', using flat');
  2031.       outform := 'flat';
  2032.     end;
  2033.  
  2034. { would do the userid and pathuserid and fromuserid earlier, but need }
  2035. { to define configdir first, and then we need to have the fullname! }
  2036.  
  2037. {can't use waffle's uucpfrom, since I use fromuserid in, say, Message-IDs}
  2038. {
  2039.   if fromuserid='' then
  2040.     fromuserid := getconfig('uucpfrom');
  2041. }
  2042.  
  2043. { debuglist: translateuserid does its own output }
  2044.   translateuserid;
  2045.  
  2046. { must expand fullname once we have the right userid, and before we try }
  2047. { to use %_ in expansion of pathuserid and fromuserid }
  2048.  
  2049.   if fullname='' then
  2050.     fullname := getfullnameforuser(userid);
  2051.  
  2052.   if fullname='' then
  2053.     begin
  2054.       xwritelnsss('user ',userid,' has no name in the password file');
  2055.       xwritelns('  that can be found, and environment variable FULLNAME');
  2056.       xwritelns('  not set, and option -f/--fullname not used');
  2057.       shutdown(1);
  2058.     end;
  2059.  
  2060.   fixpathuserid;
  2061.   fixfromuserid;
  2062.  
  2063.   fixcustomstatic;
  2064.  
  2065.  
  2066.  
  2067. {finally do user's rc file options, which MIGHT not use restricted options}
  2068.  
  2069. {done as early as possible to allow user to use --quiet usefully}
  2070.  
  2071.   if xiface=ifacewaffle then
  2072.     home := withbackslash(userdir)+userid;
  2073.  
  2074.   if xiface=ifaceuupc then
  2075.     home := unslash(unbackslash(getconfig('home')));
  2076.  
  2077.   if xiface=ifaceuufree then
  2078.     home := withbackslash(userdir)+userid;
  2079.  
  2080.   if home='' then
  2081.     begin
  2082.       xwritelns('unknown home directory');
  2083.       shutdown(1);
  2084.     end;
  2085.   
  2086. {waste of time - tpascal doesn't use filemode on text files!}
  2087.  
  2088.   oldfilemode := filemode;
  2089.   if not nofilemode then
  2090.     filemode := $40;   {read only, deny none}
  2091.  
  2092.   rcfilename := withbackslash(home)+newsreadername+'.rc';
  2093.  
  2094.   safereset(rcf,rcfilename);
  2095.   if fileresult=0 then
  2096.     begin
  2097.       while not eof(rcf) do
  2098.         begin
  2099.           readln(rcf,rcval);
  2100.           rctag := chopfirstw(rcval);
  2101.           if length(rctag)>0 then
  2102.             if (rctag[1]<>'#') and (rctag[1]<>';') then
  2103.               begin
  2104.                 if rctag[1]<>'-' then
  2105.                   rctag := '--'+rctag;
  2106.  
  2107. {very important that this is marked as `suspicious' value (third arg)!}
  2108. {because it's from the user's rnr.rc file}
  2109.  
  2110.                 if handleoption(lower(rctag),rcval,issuspicious) then
  2111.                   ;
  2112.               end;
  2113.         end;
  2114.       close(rcf);
  2115.     end
  2116.   else
  2117.     xwritelnsss('(could not open rc file ',rcfilename,')');
  2118.  
  2119.   filemode := oldfilemode;
  2120.  
  2121. {finally done reading options}
  2122.  
  2123.   if idleminutes=0 then
  2124.     if trusted then
  2125.       idleminutes := 60
  2126.     else
  2127.       idleminutes := 5;
  2128.  
  2129.   notquietlnss('full name: ',fullname);
  2130.  
  2131. {}{} {needs to get editor entry from password and extern/_editors files}
  2132.  
  2133.   if (editor='') and not ignoreenvironment then
  2134.     editor := getenv('VISUAL');
  2135.   if (editor='') and not ignoreenvironment then
  2136.     editor := getenv('EDITOR');
  2137.   if editor='' then
  2138.     editor := 'vi';
  2139.  
  2140.   notquietlnss('editor: ',editor);
  2141.  
  2142.   if (vspeller='') and not ignoreenvironment then
  2143.     vspeller := getenv('VSPELL');
  2144.   if (vspeller='') and not ignoreenvironment then
  2145.     vspeller := getenv('SPELL');
  2146.   if vspeller='' then
  2147.     vspeller := 'vspell';
  2148.  
  2149.   notquietlnss('vspeller: ',vspeller);
  2150.  
  2151.   if not quiet and (minutestorun>=0) then
  2152.     if minutestorun>24*60 then
  2153.       xwritelnsi('days left this session: ',minutestorun div 60 div 24)
  2154.     else if minutestorun>60 then
  2155.       xwritelnsi('hours left this session: ',minutestorun div 60)
  2156.     else
  2157.       xwritelnsi('minutes left this session: ',minutestorun);
  2158.  
  2159.   uucpname := getconfig('uucpname');
  2160.   fqdn := getconfig('fqdn');
  2161.   organ := getconfig('organ');
  2162.  
  2163.   newsname := default(uucpname,getconfig('newsname'));
  2164.  
  2165.   smarthost := getconfig('smarthost');
  2166.   if (smarthost='') and (xiface=ifaceuupc) then
  2167.     smarthost := uupcgetconfig('newsserv');
  2168.  
  2169.   if (uucpname='') or (smarthost='') then
  2170.     begin
  2171.       xwritelns('invalid uucpname or smarthost static variable');
  2172.       xwritelns('  neither of these may be empty');
  2173.       xwritelns('  current values:');
  2174.       xwritelnss('  uucpname:  ',uucpname);
  2175.       xwritelnss('  smarthost: ',smarthost);
  2176.       shutdown(1);
  2177.     end;
  2178.  
  2179.   smarthostdir := smarthost;
  2180.   if pos('!',smarthostdir)<>0 then
  2181.     smarthostdir := copy(smarthost,1,pos('!',smarthostdir)-1);
  2182.   smarthostdir := withbackslash(spooldir)+smarthostdir;
  2183.  
  2184.   maybemkhier(home);
  2185.   maybemkhier(outboxdir);
  2186.   maybemkhier(temporarydir);
  2187.  
  2188.   backbone := getconfig('backbone');
  2189.   if backbone='' then
  2190.     begin
  2191. {use waffle's default}
  2192.       notquietlns('no backbone variable -- using berkeley');
  2193.       backbone := 'ucbvax.berkeley.edu';
  2194.     end;
  2195.  
  2196.   if mailprefix='' then
  2197.     mailprefix := uucpname+'.mail';
  2198.  
  2199. {make life easier later - redefine mailprefix to include userid}
  2200.  
  2201.   mailprefix := mailprefix+'.'+userid;
  2202.  
  2203.   notquietlnss('mail groups begin with ',mailprefix);
  2204.  
  2205. {this way can be much quicker than using default}
  2206.   if netmail='' then
  2207.     netmail := getconfig('netmail');
  2208.  
  2209.   if netnews='' then
  2210.     netnews := getconfig('netnews');
  2211.  
  2212.   if replyto='' then
  2213.     replyto := getconfig('replyto');
  2214.  
  2215. {here calling default doesn't hurt}
  2216.   netmail := default('%A@%n (%W)',netmail);
  2217.   netnews := default(netmail,netnews);
  2218.  
  2219.   mailfrom := wafexpand(netmail);
  2220.   newsfrom := wafexpand(netnews);
  2221.   if replyto<>'' then
  2222.     replyto := wafexpand(replyto);
  2223.  
  2224.   if
  2225.       hasno('.',fqdn)
  2226.    or
  2227.       (numoccur('@',mailfrom)>1)
  2228.    or
  2229.       (numoccur('@',newsfrom)<>1)
  2230.    or
  2231.       (numoccur('@',replyto)>1)
  2232.    or
  2233.       (pos('@.',mailfrom)<>0)
  2234.    or
  2235.       (pos('@.',newsfrom)<>0)
  2236.    or
  2237.       (pos('@.',replyto)<>0)
  2238.    or
  2239.       (
  2240.         hasno('@',mailfrom) and hasno('!',mailfrom)
  2241.       )
  2242.    or
  2243.       (
  2244.         (replyto<>'') and hasno('@',replyto) and hasno('!',replyto)
  2245.       )
  2246.    or
  2247.       (
  2248.         hasany('(',newsfrom) and
  2249.           (
  2250.                (numoccur('(',newsfrom)<>1)
  2251.             or (numoccur(')',newsfrom)<>1)
  2252.             or (numoccur('<',newsfrom)<>0)
  2253.             or (numoccur('>',newsfrom)<>0)
  2254.           )
  2255.       )
  2256.  
  2257.    then
  2258.  
  2259.     begin
  2260.       xwritelns('invalid node: or netmail:/netnews:/replyto: static entry');
  2261.       xwritelns('  the node (fqdn) entry needs at least one "."');
  2262.       xwritelns('  the netmail entry needs one "@" and/or at least one "!"');
  2263.       xwritelns('  the netnews entry needs one "@"');
  2264.       xwritelns('  the netnews entry cannot have any of ()<> inside the ()');
  2265.       xwritelns('  any replyto entry needs one "@" and/or at least one "!"');
  2266.       xwritelns('  @. is never legal in a mail address');
  2267.       xwriteln;
  2268.       xwritelns('current settings:');
  2269.       xwritelnss('  node:     ',fqdn);
  2270.       xwritelnss('  newsfrom: ',newsfrom);
  2271.       xwritelnss('  mailfrom: ',mailfrom);
  2272.       xwritelnss('  replyto:  ',replyto);
  2273.       shutdown(1);
  2274.     end;
  2275.  
  2276.  
  2277.  
  2278.   notquietlnss('mail from: ',mailfrom);
  2279.  
  2280.   if mailfrom<>newsfrom then
  2281.     notquietlnss('news from: ',newsfrom);
  2282.  
  2283.   if replyto<>'' then
  2284.     if not quiet then
  2285.       begin
  2286.         if replyto=mailfrom then
  2287.           xwritelnss('reply-to: ','(same as mail)')
  2288.         else if replyto=newsfrom then
  2289.           xwritelnss('reply-to: ','(same as news)')
  2290.         else
  2291.           xwritelnss('reply-to: ',replyto);
  2292.       end;
  2293.  
  2294.   maymail := true;
  2295.   maypost := true;
  2296.  
  2297.   if pos('@no.such.domain',mailfrom)<>0 then
  2298.     begin
  2299.       maymail := false;
  2300.       xwritelns('unconfigured -- you may not mail');
  2301.     end;
  2302.  
  2303.   if pos('@no.such.domain',newsfrom)<>0 then
  2304.     begin
  2305.       maypost := false;
  2306.       xwritelns('unconfigured -- you may not post');
  2307.     end;
  2308.  
  2309.   fixnewscmdline;
  2310.   fixmailcmdline;
  2311.  
  2312.   if forumsetl='' then
  2313.     forumsetl := getconfig('forums');
  2314.  
  2315.   forumsetl := ltrim(trim(forumsetl));
  2316.  
  2317.   if (forumsetl='') and (xiface=ifaceuupc) then
  2318.     forumsetl := 'active';
  2319.  
  2320.   if forumsetl='' then
  2321.     begin
  2322.       xwritelns('empty forum set list');
  2323.       shutdown(1);
  2324.     end;
  2325.  
  2326.   notquietlnss('forum set list: ',forumsetl);
  2327.  
  2328.   if not ignoreenvironment then
  2329.     timezone := getenv('TZ');
  2330.  
  2331.   if timezone='' then
  2332.     timezone := getconfig('timezone');
  2333.   if timezone='' then
  2334.     timezone := '-0700';
  2335.   if pos(' ',timezone)>1 then
  2336.     timezone := copy(timezone,1,pos(' ',timezone)-1)
  2337.   else if (timezone[1]<>'+') and (timezone[1]<>'-') then
  2338.     timezone := copy(timezone,1,3);
  2339. { handles TZ=GMT0BST and TZ=+1100 and TZ=BST-1 cases }
  2340.  
  2341. {}{}{} {need to do more checking on the timezone!}
  2342.  
  2343.   notquietlnss('timezone: ',timezone);
  2344.  
  2345.   comspec := getenv('COMSPEC');
  2346.   if comspec='' then
  2347.     if indir('c:\.','command.com') then
  2348.       comspec := 'c:\command.com'
  2349.     else
  2350.       comspec := 'command.com';
  2351.  
  2352.   notquietlnss('newscmdline: ',newscmdline);
  2353.   notquietlnss('mailcmdline: ',mailcmdline);
  2354.  
  2355. {once joinfn is assigned to a nonempty string, it's open}
  2356.  
  2357.   joinfn := home+'\join';
  2358.   safereset(joinf,joinfn);
  2359.   if fileresult<>0 then
  2360.     begin
  2361.       xwritelnsss('join file ',joinfn,' not found.');
  2362.       joinfn := '';
  2363.       shutdown(1);
  2364.     end;
  2365.  
  2366.   numjoined := 0;
  2367.   backupjoin;
  2368.  
  2369.   readinkill(yesbackupkill);
  2370.   readinantikill(yesbackupkill);
  2371.  
  2372.   if currsource<>'' then
  2373.     if not expandsource(currsource,currsourcekind) then
  2374.       begin
  2375.         xwritelnss('you are not joined to ',currsource);
  2376.         xwritelns('and it does not look like a valid directory, so');
  2377.         xwritelns('I will start at the top of the join file');
  2378.         currsource := '';
  2379.         needtofindnextgroup := true;
  2380.       end;
  2381.  
  2382.   fixuplppcols;
  2383.  
  2384.   if not quiet then
  2385.     begin
  2386.       xwritelnsi('lines per page: ',lpp);
  2387.       xwritelnsi('sel lines per page: ',sellpp);
  2388.       xwritelnsi('columns: ',cols);
  2389.       if usebiosforscreen then
  2390.         xwritelns('(using bios for screen writes)');
  2391.       if hideformfeeds then
  2392.         xwritelns('(hiding form feeds)');
  2393.     end;
  2394.  
  2395.   if console then
  2396.     begin
  2397.       fixcolors;
  2398.       mouseinit;
  2399.     end;
  2400.  
  2401.   xlowvideo;
  2402.  
  2403.   if outgoingmail<>'' then
  2404.     begin
  2405.       unfoldergroup(outgoingmail);
  2406.       if not ismailgroup(outgoingmail) then
  2407.         outgoingmail := '='+outgoingmail;
  2408.       unfoldergroup(outgoingmail);
  2409.       xwritelnss('copies of outgoing mail will be put in ',outgoingmail);
  2410.     end;
  2411.  
  2412.   if uselocalcharset then
  2413.     begin
  2414.       loadcharsets(localcharsetfn);
  2415.     end;
  2416.  
  2417.   if wantedtogotosource then
  2418.     begin
  2419.  
  2420. { make sure last line had no valuable information }
  2421.       xgotoxy(1,lpp);
  2422.       xwriteln;
  2423.  
  2424.       pickasource(currsource,currsourcekind);
  2425.       if currsource<>'' then
  2426.         needtofindnextgroup := false;
  2427.     end;
  2428. end;
  2429.  
  2430. end.
  2431.